
<%

	var p = {
		id:id!"",//required="true" description="编号"
		name:name!"",//required="true" description="隐藏域名称（ID）"
		value:value!"",//required="true" description="隐藏域值（ID）"
		labelName:labelName!"",//required="true" description="输入框名称（Name）"
		labelValue:labelValue!"",//required="true" description="输入框值（Name）"
		title:title!"",//required="true" description="选择框标题"
		url:url!"",//required="true" description="树结构数据地址"
		
		//checked:(checked!"false")=="true"?true:false,//required="false" description="是否显示复选框，如果不需要返回父节点，请设置notAllowSelectParent为true"
		checked:(checked!"")=="true"?"true":"",
		extId:extId!"",//required="false" description="排除掉的编号（不能选择的编号）"
		isAll:isAll!"",//required="false" description="是否列出全部数据，设置true则不进行数据权限过滤（目前仅对Office有效）"
		notAllowSelectRoot:(notAllowSelectRoot!"true")=="true"?true:false,//required="false" description="不允许选择根节点"
		notAllowSelectParent:(notAllowSelectParent!"true")=="true"?true:false,//required="false" description="不允许选择父节点"
		module:module!"",//required="false" description="过滤栏目模型（只显示指定模型，仅针对CMS的Category树）"
		selectScopeModule:(selectScopeModule!"false")=="true"?true:false,//required="false" description="选择范围内的模型（控制不能选择公共模型，不能选择本栏目外的模型）（仅针对CMS的Category树）"
		allowClear:(allowClear!"false")=="true"?true:false,//required="false" description="是否允许清除"
		allowInput:(allowInput!"false")=="true"?true:false,//required="false" description="文本框可填写"
		cssClass:cssClass!"",//required="false" description="css样式"
		cssStyle:cssStyle!"",//required="false" description="css样式"
		smallBtn:(smallBtn!"false")=="true"?true:false,//required="false" description="缩小按钮显示"
		hideBtn:(hideBtn!"false")=="true"?true:false,//required="false" description="是否显示按钮"
		disabled:disabled!"",//required="false" description="是否限制选择，如果限制，设置为disabled"
		dataMsgRequired:dataMsgRequired!"",//required="false" description=""
		
		isSubTag:(isSubTag!"true")=="true"?true:false // 是否是嵌套在自定义标签#form里面
	};
	
	var height = "90%";
	var shade = 0;
	if(p.isSubTag) {
		height = "80%";
		shade = 0.3;
	}
%>

<div class="input-group">
	<input id="${p.id}Id" name="${p.name}" class="${p.cssClass}" type="hidden" value="${p.value}"/>
	<input id="${p.id}Name" name="${p.labelName}" ${p.allowInput?'':'readonly="readonly"'} type="text" value="${p.labelValue}" data-msg-required="${p.dataMsgRequired}"
		class="form-control ${p.cssClass}" style="${p.cssStyle}"/>
	<span class="input-group-btn">
		<a id="${p.id}Button" href="javascript:" class="btn btn-default ${p.disabled} ${p.hideBtn ? 'hide' : ''}" style="${p.smallBtn?'padding:4px 2px;':''}"><i class="fa fa-search"></i></a>
    </span>
    
</div>
<script type="text/javascript">
<% if(p.isSubTag) { %>
	<![CDATA[
<%}%>
$("#${id}Button, #${id}Name").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#${id}Button").hasClass("disabled")){
			return true;
		}
		
		layer.open({
			  type: 2,
			  title: '选择${p.title}',
			  shadeClose: true,
			  scrollbar: false,
			  shade: ${shade},
			  area: ['280px', '${height}'],
			  content: "${ctx}/tag/treeselectNew?url=${p.url}&module=${p.module}&checked=${p.checked}&extId=${p.extId}&isAll=${p.isAll}&selectIds=$('#${p.id}Id').val()", //iframe的url
			  btn: ['<i class="fa fa-plus"></i> 确定', '<i class="fa fa-times"></i> 取消'],
			  btn1: function(index, layero){
				  var win = layer.iframeWindow(index);
				  
				  var tree = win.tree;//$("#tree");//h.find("iframe").contents();
					var ids = [], names = [], nodes = [];
					if ("${p.checked}" == "true"){
						nodes = tree.getCheckedNodes(true);
					}else{
						nodes = tree.getSelectedNodes();
					}
					for(var i=0; i<nodes.length; i++) {
						/* if (nodes[i].isParent){
							continue; // 如果为复选框选择，则过滤掉父节点
						} 
						if (nodes[i].level == 0){
							js.showMessage("不能选择根节点（"+nodes[i].name+"）请重新选择。");
							return false;
						}
						if (nodes[i].isParent){
							js.showMessage("不能选择父节点（"+nodes[i].name+"）请重新选择。");
							return false;
						}*/
						if (nodes[i].module == ""){
							js.showMessage("不能选择公共模型（"+nodes[i].name+"）请重新选择。");
							return false;
						}else if (nodes[i].module != null){
							js.showMessage("不能选择当前栏目以外的栏目模型，请重新选择。" + nodes[i].module);
							return false;
						}
						ids.push(nodes[i].id);
						names.push(nodes[i].name);
						break; // 如果为非复选框选择，则返回第一个选择  
					}
					$("#${p.id}Id").val(ids.join(",").replace(/u_/ig,""));
					$("#${p.id}Name").val(names.join(","));
				  
				  
				  layer.close(index);
		    	},
			  btn2: function(index, layero){
				  
		    	}
		}); 
		
	});
<% if(p.isSubTag) { %>
	]]>
<%}%>
</script>